package main

import (
	"log"
	"net/http"

	"vod-service/config"  // 替换为实际项目路径
	"vod-service/handler" // 替换为实际项目路径

	"github.com/gin-contrib/cors"
	"github.com/gin-gonic/gin"
)

func main() {
	// 初始化配置
	config.Init()

	// 初始化Gin引擎
	r := gin.Default()
	r.LoadHTMLGlob("templates/**")
	// 配置CORS（允许跨域访问）
	r.Use(cors.New(cors.Config{
		AllowOrigins:     []string{"*"}, // 生产环境建议指定具体域名
		AllowMethods:     []string{"GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"},
		AllowHeaders:     []string{"Origin", "Content-Type", "Accept"},
		ExposeHeaders:    []string{"Content-Length"},
		AllowCredentials: true,
	}))
	handler.RegisterSpaceRoutes(r)
	handler.RegisterMaterialRoutes(r)
	handler.RegisterMediaRoutes(r)
	handler.RegisterVodRoutes(r)
	handler.RegisterPlayRoutes(r)
	// 启动服务
	log.Printf("服务启动成功，监听端口: %s\n", config.Conf.Port)
	if err := http.ListenAndServe(":"+config.Conf.Port, r); err != nil {
		log.Fatalf("服务启动失败: %v", err)
	}
}
